package com.ruoyi.wb.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.wb.domain.WbPlanClassifyYearContent;
import com.ruoyi.wb.domain.WbPlanClassifyYearContentThree;
import com.ruoyi.wb.mapper.WbPlanClassifyYearContentMapper;
import com.ruoyi.wb.service.IWbPlanClassifyYearContentService;
import com.ruoyi.wb.service.IWbPlanClassifyYearContentThreeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 维保年度类目二级Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-11-15
 */
@Service
public class WbPlanClassifyYearContentServiceImpl implements IWbPlanClassifyYearContentService 
{
    @Autowired
    private WbPlanClassifyYearContentMapper wbPlanClassifyYearContentMapper;

    @Autowired
    private IWbPlanClassifyYearContentThreeService wbPlanClassifyYearContentThreeService;

    /**
     * 查询维保年度类目二级
     * 
     * @param classifyYearContentId 维保年度类目二级主键
     * @return 维保年度类目二级
     */
    @Override
    public WbPlanClassifyYearContent selectWbPlanClassifyYearContentByClassifyYearContentId(Long classifyYearContentId)
    {
        return wbPlanClassifyYearContentMapper.selectWbPlanClassifyYearContentByClassifyYearContentId(classifyYearContentId);
    }

    /**
     * 查询维保年度类目二级列表
     * 
     * @param wbPlanClassifyYearContent 维保年度类目二级
     * @return 维保年度类目二级
     */
    @Override
    public List<WbPlanClassifyYearContent> selectWbPlanClassifyYearContentList(WbPlanClassifyYearContent wbPlanClassifyYearContent)
    {
        return wbPlanClassifyYearContentMapper.selectWbPlanClassifyYearContentList(wbPlanClassifyYearContent);
    }

    /**
     * 新增维保年度类目二级
     * 
     * @param wbPlanClassifyYearContent 维保年度类目二级
     * @return 结果
     */
    @Override
    public int insertWbPlanClassifyYearContent(WbPlanClassifyYearContent wbPlanClassifyYearContent)
    {
        wbPlanClassifyYearContent.setCreateTime(DateUtils.getNowDate());
        return wbPlanClassifyYearContentMapper.insertWbPlanClassifyYearContent(wbPlanClassifyYearContent);
    }

    /**
     * 修改维保年度类目二级
     * 
     * @param wbPlanClassifyYearContent 维保年度类目二级
     * @return 结果
     */
    @Override
    public int updateWbPlanClassifyYearContent(WbPlanClassifyYearContent wbPlanClassifyYearContent)
    {
        wbPlanClassifyYearContent.setUpdateTime(DateUtils.getNowDate());
        return wbPlanClassifyYearContentMapper.updateWbPlanClassifyYearContent(wbPlanClassifyYearContent);
    }

    /**
     * 批量删除维保年度类目二级
     * 
     * @param classifyYearContentIds 需要删除的维保年度类目二级主键
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteWbPlanClassifyYearContentByClassifyYearContentIds(Long[] classifyYearContentIds)
    {
        //查询三级

        List<WbPlanClassifyYearContentThree>  wbPlanClassifyYearContentThrees=wbPlanClassifyYearContentThreeService.selectWbPlanClassifyYearContentThreeListByClassifyYearContentIds(classifyYearContentIds);

      Long[] classifyContentIds= wbPlanClassifyYearContentThrees.stream().map(WbPlanClassifyYearContentThree::getClassifyContentId).toArray(Long[]::new);
      if (classifyContentIds.length>0){
          //删除三级
          wbPlanClassifyYearContentThreeService.deleteWbPlanClassifyYearContentThreeByClassifyContentIds(classifyContentIds);
      }


        //删除二级
        return wbPlanClassifyYearContentMapper.deleteWbPlanClassifyYearContentByClassifyYearContentIds(classifyYearContentIds);
    }

    /**
     * 删除维保年度类目二级信息
     * 
     * @param classifyYearContentId 维保年度类目二级主键
     * @return 结果
     */
    @Override
    public int deleteWbPlanClassifyYearContentByClassifyYearContentId(Long classifyYearContentId)
    {
        return wbPlanClassifyYearContentMapper.deleteWbPlanClassifyYearContentByClassifyYearContentId(classifyYearContentId);
    }
    /**
     * 批量新增维保年度类目二级
     */
    @Override
    public int batchAdd(List<WbPlanClassifyYearContent> wbPlanClassifyYearContents) {
        return  wbPlanClassifyYearContentMapper.batchAdd(wbPlanClassifyYearContents);
    }
}
